/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converter;


import entities.Prize;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Chien
 */
@FacesConverter(forClass=Prize.class)
public class PrizeConverter implements javax.faces.convert.Converter{
    private Prize users;
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (users == null) {
            users = new Prize(Integer.valueOf(value));
            return users;
        } else {
            throw new ConverterException(new FacesMessage(String.format("Can not convert %s to Prize", value)));
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return String.valueOf(((Prize)value).getPrizeId());
    }
    
}
